package com.chengyu.core;

import com.github.houbb.sensitive.word.api.IWordDeny;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class MyWordDeny implements IWordDeny {
    @Value("classpath:myDenyWords.txt")
    private Resource resourceDeny;

    @Override
    public List<String> deny() {
        List<String> denyWords = new ArrayList<>();

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceDeny.getInputStream(), StandardCharsets.UTF_8))) {
            denyWords = reader.lines().collect(Collectors.toList());
            log.info("1============读取禁用词语个数：{}",denyWords.size());
        }catch (Exception e){
            throw new RuntimeException(e);
        }
        return denyWords;
    }
}
